from flask import Flask
from flask import render_template,request
'''
优特编程  Python 常见程序交互界面之 Web Flask 快速示例
set flask_env=development
flask run
'''
app = Flask(__name__)


@app.route('/', methods=["Get", "Post"])
def hello_world():
    return 'Hello World!'

# 得到前段输入的数据，并反馈计算结果给前端
@app.route('/mybmi', methods=["GET", "POST"])
def mybmi():
    bmi = 0.0
    if request.method == "POST":
        w = float(request.form['weight'])
        h = float(request.form.get('height'))
        bmi = w/(h**2)

    return render_template("bmi.html", bmi=round(bmi,2))

if __name__ == '__main__':
    app.run(debug=True)
